﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace cadbom
{
    public partial class BaiGeForm : Form
    {
        BaigeProcess process = null;
        NetApi netApi = new NetApi();
        public BaiGeForm()
        {
            netApi.InitDomainConfig();
            netApi.getUserInfo();
            process = new BaigeProcess();
            InitializeComponent();
            process.ReadLayer0XData();
            this.textBox1.Text = GValues.CADMainProductCode;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            process.UnlockAllLayersAndReadObject(new Action<List<Dictionary<String, Dictionary<String, String>>>>(r =>
            {
                //netApi.saveProcessBom(r, new Action<string>(result =>
                //{

                //    int i = 0;
                //    r.ForEach(p =>
                //    {
                //        i++;
                //        this.richTextBox1.AppendText("第" + i + "图" + " \n");
                //        foreach (var key in p.Keys)
                //        {
                //            //BomForm bomForm = new BomForm();
                //            //bomForm.TT7SaveBomFormData(key, result);


                //            this.richTextBox1.AppendText("产品 : " + key + " \n");
                //            foreach (var key1 in p[key].Keys)
                //            {
                //                this.richTextBox1.AppendText(key1 + ":" + p[key][key1] + " \n");
                //            }
                //        }


                //    });
                //}));

            }));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.button1.Enabled = true;
            process.ExecuteLisp(new Action<String>(r =>
            {
                // 假设这是你的Form类的一个方法
                this.Invoke(new Action(() =>
                {
                    // 更新UI的代码
                    this.richTextBox1.AppendText(" 坐标点读取完成!\n");
                }));

            }));
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void splitContainer1_Panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            process.GetAllProductCodeAndQty(new Action<CadProductBom>(mainBom => {
                MessageBox.Show(mainBom.code + mainBom.boms.Count());
                netApi.saveSemiProductBom(mainBom, new Action<string>(r =>
                {
                    MessageBox.Show(r);
                }));
            }));
        }

    }
}
